﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMeterParamFrame.Model.DIValueConverters
{
    /// <summary>
    /// 电压，电流互感器转换类
    /// </summary>
    class Converter_HuGan : IDIDataConverter
    {
        static uint HUGAN_CURRENT = uint.Parse("04000306", System.Globalization.NumberStyles.AllowHexSpecifier);
        static uint HUGAN_VOLTAGE = uint.Parse("04000307", System.Globalization.NumberStyles.AllowHexSpecifier);

        public bool CanConverter(string di)
        {
            uint udi = uint.Parse(di, System.Globalization.NumberStyles.AllowHexSpecifier);

            if (udi == HUGAN_CURRENT || udi == HUGAN_VOLTAGE)
                return true;

            return false;
        }

        public string ConvertToUI(string di, string value)
        {
            int firstPositiveIndex = value.IndexOfAny(DIValueConverter.NUMBER_POSITIVE);
            string newValue = value.Substring(firstPositiveIndex, value.Length - firstPositiveIndex);
            return newValue;
        }

        public string ConvertToLow(string di, string value)
        {
            string newValue = value.PadLeft(6, '0');
            return newValue;
        }

        public bool ValidateValue(string di, string value)
        {
            throw new NotImplementedException();
        }
    }
}
